import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class JButtonExample extends WindowAdapter implements ActionListener {
    private JFrame mJFrame;
    private JButton mJButton;
    private JTextField mJTextField;
    private int mTag = 0;
    public static void main(String args[]) {
        JButtonExample example = new JButtonExample();
        example.go();
    }

    public void go() {
        mJFrame = new JFrame("JButtonExample");
        mJButton = new JButton("Sample");
        mJButton.addActionListener(this);
        mJFrame.getContentPane().add(mJButton,"South");
        mJTextField = new JTextField();
        mJFrame.getContentPane().add(mJTextField,"Center");
        mJFrame.addWindowListener(this);
        mJFrame.setSize(300,200);
        mJFrame.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        String s1 = "You have pressed Button!";
        String s2 = "You do another time!";
        if (mTag == 0) {
            mJTextField.setText(s1);
            mTag = 1;
        } else {
            mJTextField.setText(s2);
            mTag = 0;
        }
    }

    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
}
